package com.an.common.enums;

import cn.hutool.core.util.StrUtil;
import com.an.common.constant.BlogConstants;
import com.an.common.constant.CacheConstants;
import com.an.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 代码模板类型
 *
 * @author: Ann
 * @createDate: 2023/08/03 14:13:20
 * @version: 1.0.0
 */
@Getter
@AllArgsConstructor
public enum CodeTemplateType {


    /**
     * 登录模板
     */
    LOGIN_TEMPLATE("0", BlogConstants.MAIL_LOGIN_SEND_SUBJECT, BlogConstants.MAIL_LOGIN_SEND_CODE_TEMPLATE,
        CacheConstants.MAIL_LOGIN_CODE_KEY),

    /**
     * 注册模板
     */
    REGISTER_TEMPLATE("1", BlogConstants.MAIL_REGISTER_SEND_SUBJECT, BlogConstants.MAIL_REGISTER_SEND_CODE_TEMPLATE,
        CacheConstants.MAIL_REGISTER_CODE_KEY),

    /**
     * 忘记模板
     */
    FORGOT_TEMPLATE("2", BlogConstants.MAIL_FORGOT_SEND_SUBJECT, BlogConstants.MAIL_FORGOT_SEND_CODE_TEMPLATE,
        CacheConstants.MAIL_FORGOT_CODE_KEY),


    /**
     * 好友链接提醒模板
     */
    FRIEND_LINK_REMIND_TEMPLATE("3", BlogConstants.MAIL_FRIEND_LINK_REMIND_SEND_SUBJECT, BlogConstants.MAIL_FRIEND_LINK_REMIND_TEMPLATE,
        StringUtils.EMPTY);

    private final String type;

    private final String subject;

    private final String content;

    private final String keyPrefix;

    /**
     * 找到模板
     *
     * @param type 类型
     * @return {@link CodeTemplateType }
     * @author: Ann
     * @createDate: 2023/08/03 14:18:04
     * @version: 1.0.0
     */
    public static CodeTemplateType findTemplate(String type) {
        if (StringUtils.isBlank(type)) {
            return null;
        }
        for (CodeTemplateType value : values()) {
            if (value.getType().equals(type)) {
                return value;
            }
        }
        return null;
    }

}
